package com.jerry.base.thread;

import lombok.extern.slf4j.Slf4j;

/**
 * User: Jerry
 * Date: 2024/2/5
 * Time: 10:42
 * Description:
 */
@Slf4j
public class ThreadState {

    static class T extends Thread {
        @Override
        public void run() {
            while (true) {
                for (int i = 1; i <= 10; i++) {
                    log.info("T执行了{}次", i);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                break;
            }
        }
    }

    public static void main(String[] args) {
        T t = new T();
        log.info("T线程的状态：{}", t.getState());
        t.start();

        while (Thread.State.TERMINATED != t.getState()) {
            log.info("T线程的状态：{}", t.getState());
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        log.info("T线程的状态：{}", t.getState());
    }
}
